/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   14-12-23 上午9:29 Created by dwzhang
 */
package com.jade.bss.beacon;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;

/**
 * Beacon信息定义，包括beacon标识、所有者、位置、电量及其他设置信息。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a>
 * @version 1.0 14-12-23 上午9:29
 */
@Entity
@Table (name = "BSS_BEACON")
public class Beacon
        implements Serializable
{
    @Transient
    protected Map<Class, BeaconExtInfo> infos;
    /** Beacon唯一标识 */
    @Id
    @GeneratedValue (generator = "BSS_SEQ_BEACON")
    @SequenceGenerator (name = "BSS_SEQ_BEACON", sequenceName = "BSS_SEQ_BEACON")
    private long id;
    /** Beacon设备名称 */
    @Column (name = "name", length = 32)
    private String name;
    /** Beacon状态 */
    @Column (name = "status")
    private int status;
    /** 设备型号 */
    @Column (name = "device_model", length = 32)
    private String deviceModel;
    /** 设备批次 */
    @Column (name = "batch_no", length = 32)
    private String batchNo;
    /** 创建时间 */
    @Column (name = "creation_time", nullable = false, updatable = false)
    private Date creationTime;
    /** 最近更新时间 */
    @Column (name = "last_update_time")
    private Date lastUpdateTime;
    /** beacon所有者类型 */
    @Column (name = "owner_type", length = 32)
    private String ownerType;
    /** beacon所有着标识 */
    @Column (name = "owner_id", length = 64)
    private String ownerId;
    /*
    应用id
     */
    @Column (name = "app_id")
    private long appId = 0;
    /*
    应用类型
     */
    @Column (name = "app_type")
    private String appType;
    /** beacon位置描述 */
    @Column (name = "loc", length = 64)
    private String loc;
    /** beacon 图片*/
    @Column (name = "picture", length = 64)
    private String picture;
    /** beacon所在位置的地理位置，一般根据所有者位置来定*/
    @Column (name = "lat")
    private long lat;
    @Column (name = "lng")
    private long lng;
    @Column (name = "remark", length = 64)
    private String remark;
    /** mac 地址 */
    @Column (name = "mac_address", length = 64)
    private String macAddress;
    /** The proximity ID of the beacon */
    @Column (name = "proximity_uuid", length = 64)
    private String proximityUUID;
    /** The most significant value in the beacon. */
    @Column (name = "major")
    private int major;
    /** The least significant value in the beacon. */
    @Column (name = "minor")
    private int minor;
    /** Factory calibrated constant indicating the expected RSSI value at the distance of 1 meter from the beacon. */
    @Column (name = "measured_power")
    private int measuredPower;
    /** 发射功率,单位db */
    @Column (name = "transmit_power")
    private int transmitPower;
    /** 发射间隔，毫秒为单位*/
    @Column (name = "transmit_interval")
    private int transmitFrequency;
    /** 固件版本 */
    @Column (name = "firmware_version")
    private int firmwareVersion;
    /** 硬件版本 */
    @Column (name = "hardware_version")
    private int hardwareVersion;
    /** 电源模式 */
    @Column (name = "power_mode")
    private int powerMode;
    /** 电池类型 */
    @Column (name = "battery_type")
    private int batteryType;
    /** 电量水平，百分比 */
    @Column (name = "battery_level")
    private int batteryLevel;
    /** 剩余电量维持的天数 */
    @Column (name = "battery_level_in_days")
    private int batteryLevelInDays;

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public String getDeviceModel()
    {
        return deviceModel;
    }

    public void setDeviceModel(String deviceModel)
    {
        this.deviceModel = deviceModel;
    }

    public String getBatchNo()
    {
        return batchNo;
    }

    public void setBatchNo(String batchNo)
    {
        this.batchNo = batchNo;
    }

    public Date getCreationTime()
    {
        return creationTime;
    }

    public void setCreationTime(Date creationTime)
    {
        this.creationTime = creationTime;
    }

    public Date getLastUpdateTime()
    {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime)
    {
        this.lastUpdateTime = lastUpdateTime;
    }

    public String getOwnerType()
    {
        return ownerType;
    }

    public void setOwnerType(String ownerType)
    {
        this.ownerType = ownerType;
    }

    public String getOwnerId()
    {
        return ownerId;
    }

    public void setOwnerId(String ownerId)
    {
        this.ownerId = ownerId;
    }

    public String getLoc()
    {
        return loc;
    }

    public void setLoc(String loc)
    {
        this.loc = loc;
    }

    public String getPicture()
    {
        return picture;
    }

    public void setPicture(String picture)
    {
        this.picture = picture;
    }

    public long getLat()
    {
        return lat;
    }

    public void setLat(long lat)
    {
        this.lat = lat;
    }

    public long getLng()
    {
        return lng;
    }

    public void setLng(long lng)
    {
        this.lng = lng;
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public String getProximityUUID()
    {
        return proximityUUID;
    }

    public void setProximityUUID(String proximityUUID)
    {
        this.proximityUUID = proximityUUID;
    }

    public int getMajor()
    {
        return major;
    }

    public void setMajor(int major)
    {
        this.major = major;
    }

    public int getMinor()
    {
        return minor;
    }

    public void setMinor(int minor)
    {
        this.minor = minor;
    }

    public String getMacAddress()
    {
        return macAddress;
    }

    public void setMacAddress(String macAddress)
    {
        this.macAddress = macAddress;
    }

    public int getMeasuredPower()
    {
        return measuredPower;
    }

    public void setMeasuredPower(int measuredPower)
    {
        this.measuredPower = measuredPower;
    }

    public int getTransmitPower()
    {
        return transmitPower;
    }

    public void setTransmitPower(int transmitPower)
    {
        this.transmitPower = transmitPower;
    }

    public int getTransmitFrequency()
    {
        return transmitFrequency;
    }

    public void setTransmitFrequency(int transmitFrequency)
    {
        this.transmitFrequency = transmitFrequency;
    }

    public int getFirmwareVersion()
    {
        return firmwareVersion;
    }

    public void setFirmwareVersion(int firmwareVersion)
    {
        this.firmwareVersion = firmwareVersion;
    }

    public int getHardwareVersion()
    {
        return hardwareVersion;
    }

    public void setHardwareVersion(int hardwareVersion)
    {
        this.hardwareVersion = hardwareVersion;
    }

    public int getPowerMode()
    {
        return powerMode;
    }

    public void setPowerMode(int powerMode)
    {
        this.powerMode = powerMode;
    }

    public int getBatteryType()
    {
        return batteryType;
    }

    public void setBatteryType(int batteryType)
    {
        this.batteryType = batteryType;
    }

    public int getBatteryLevel()
    {
        return batteryLevel;
    }

    public void setBatteryLevel(int batteryLevel)
    {
        this.batteryLevel = batteryLevel;
    }

    public int getBatteryLevelInDays()
    {
        return batteryLevelInDays;
    }

    public void setBatteryLevelInDays(int batteryLevelInDays)
    {
        this.batteryLevelInDays = batteryLevelInDays;
    }

    public boolean simpleEqual(Beacon b)
    {
        return proximityUUID == null ? b.getProximityUUID() == null : proximityUUID.equals(b.getProximityUUID()) &&
                major == b.getMajor() && minor == b.getMinor();
    }

    public Map<Class, BeaconExtInfo> getInfos()
    {
        return infos;
    }

    public void setInfos(Map<Class, BeaconExtInfo> infos)
    {
        this.infos = infos;
    }

    public void addInfo(BeaconExtInfo info)
    {
        if (infos == null) {
            infos = new HashMap<Class, BeaconExtInfo>();
        }
        infos.put(info.getClass(), info);
    }

    public <T extends BeaconExtInfo> T getInfo(Class infoClass)
    {
        if (infos == null) {
            return null;
        }
        return (T) infos.get(infoClass);
    }

    public long getAppId()
    {
        return appId;
    }

    public void setAppId(long appId)
    {
        this.appId = appId;
    }

    public String getAppType()
    {
        return appType;
    }

    public void setAppType(String appType)
    {
        this.appType = appType;
    }
}
